/**
 * 为文章中的代码添加行号
 */

export default {
  render: ($dom) => {
    $dom.find('pre code').each(function(){
      let $this = $$(this);
      let $pre = $this.parent('pre');
      let lines = $this.text().split('\n').length - 1;
      let $numbering = $$('<ul/>').addClass('pre-numbering');
      $pre.addClass('has-numbering').append($numbering);

      for(let i=1; i <= lines; i++){
        $numbering.append($$('<li/>').text(i));
      }
    });
  }
}